<?php

class AdminModel extends Model{
	
	public $table='admin';
	
	public $validate=array(
	
		array('aname','nonull','名字不能为空',2,3),
		array('password','nonull','密码不能为空',2,3),
		array('code','nonull','验证码不能为空',2,3),
		
	);
	
	/*public $auto=array(
	
		array('ltime','_ltime','method',2,3),
	);
	
	public function _ltime(){
		
		return time();
		
	}*/
	
	public function validate_login(){
		
		if(!$this->create()) return FALSE;
		
		if(strtoupper(Q('post.code'))!=$_SESSION['code']){
			
			$this->error='验证码不正确';
			return FALSE;
		} 
		
		$aname=Q('post.aname');
		$password=md5(Q('post.password'));
		
		$data=$this->where(array('aname'=>$aname))->find();
		
		if($data['password']!=$password){
			
			$this->error='用户或密码不正确';
			return FALSE;
		} 
		
		
		$this->where(array('aname'=>$aname))->update(array('ltime'=>time()));
		
		return $data;
	}
	
}

